package com.yc.myspringboot.listener.demo1;

import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 使用@EventListener注解监听事件
 * 作用在方法上，可以在一个类中监听多个事件
 * @author yuancan
 *
 */
@Component
public class EventAnnotationListeners {

	@EventListener
	@Async
	public void listenerEventDemo(EventDemo event) {
		System.out.println("当前线程：" + Thread.currentThread().getName());
		try {
			Thread.sleep(30000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.err.println("----EventAnnotationListeners-----receive--" + event.getMessage() + ", source: " + event.getSource());
	}

}
